package edu.visualizetion.info.sensorcollection;

import java.io.Serializable;
import java.util.Map;

public class Record implements Serializable {

	private static final long serialVersionUID = 4313930911627481308L;

	private long time;
	private String nameOfServer;
	/*
	 * cpu使用率
	 */
	private double cpuRatio;
	
	/*
	 * memory内容
	 */
	private long memTotal;
	private long memUsed;
	private long memFree;
	private double memUsedRatio;
	private double memFreeRatio;
	/*
	 * disk吞吐
	 */
	private Map<String,Long> diskReadMap;
	private Map<String,Long> diskWriteMap;
	/*
	 * 网络信息
	 */
	
	private long netSend;
	private long netRecv;
	
	private float netSendSpeed;
	private float netRecvSpeed;
	

	public float getNetSendSpeed() {
		return netSendSpeed;
	}

	public void setNetSendSpeed(float netSendSpeed) {
		this.netSendSpeed = netSendSpeed;
	}

	public float getNetRecvSpeed() {
		return netRecvSpeed;
	}

	public void setNetRecvSpeed(float netRecvSpeed) {
		this.netRecvSpeed = netRecvSpeed;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public String getNameOfServer() {
		return nameOfServer;
	}

	public void setNameOfServer(String nameOfServer) {
		this.nameOfServer = nameOfServer;
	}

	public double getCpuRatio() {
		return cpuRatio;
	}

	public void setCpuRatio(double cpuRatio) {
		this.cpuRatio = cpuRatio*100;
	}

	public long getMemTotal() {
		return memTotal;
	}

	public void setMemTotal(long memTotal) {
		this.memTotal = memTotal;
	}

	public long getMemUsed() {
		return memUsed;
	}

	public void setMemUsed(long memUsed) {
		this.memUsed = memUsed;
	}

	public long getMemFree() {
		return memFree;
	}

	public void setMemFree(long memFree) {
		this.memFree = memFree;
	}

	public double getMemUsedRatio() {
		return memUsedRatio;
	}

	public void setMemUsedRatio(double memUsedRatio) {
		this.memUsedRatio = (float)(memUsed)/(float)(memTotal)*100;
	}

	public double getMemFreeRatio() {
		return memFreeRatio;
	}

	public void setMemFreeRatio(double memFreeRatio) {
		this.memFreeRatio = (float)(memFree)/(float)(memTotal)*100;
	}

	public Map<String, Long> getDiskReadMap() {
		return diskReadMap;
	}

	public void setDiskReadMap(Map<String, Long> diskReadMap) {
		this.diskReadMap = diskReadMap;
	}

	public Map<String, Long> getDiskWriteMap() {
		return diskWriteMap;
	}

	public void setDiskWriteMap(Map<String, Long> diskWriteMap) {
		this.diskWriteMap = diskWriteMap;
	}

	public long getNetSend() {
		return netSend;
	}

	public void setNetSend(long netSend) {
		this.netSend = netSend;
	}

	public long getNetRecv() {
		return netRecv;
	}

	public void setNetRecv(long netRecv) {
		this.netRecv = netRecv;
	}

	@Override
	public String toString() {
		return "Record [time=" + time + ", nameOfServer=" + nameOfServer + ", cpuRatio=" + cpuRatio + ", memTotal="
				+ memTotal + ", memUsed=" + memUsed + ", memFree=" + memFree + ", memUsedRatio=" + memUsedRatio
				+ ", memFreeRatio=" + memFreeRatio + ", diskReadMap=" + diskReadMap + ", diskWriteMap=" + diskWriteMap
				+ ", netSend=" + netSend + ", netRecv=" + netRecv + "]";
	}
	
	public String getCSV(){
		StringBuilder stringBuilder = new StringBuilder();
		char separator = ',';
		stringBuilder.append(time);
		stringBuilder.append(separator);
		stringBuilder.append(nameOfServer);
		stringBuilder.append(separator);
		// cpu
		stringBuilder.append(cpuRatio);
		stringBuilder.append(separator);
		// memory
		stringBuilder.append(memTotal);
		stringBuilder.append(separator);
		
		stringBuilder.append(memUsed);
		stringBuilder.append(separator);
		stringBuilder.append(memUsedRatio);
		stringBuilder.append(separator);
		
		stringBuilder.append(memFree);
		stringBuilder.append(separator);
		stringBuilder.append(memFreeRatio);
		stringBuilder.append(separator);
		
		// net
		stringBuilder.append(netSend);
		stringBuilder.append(separator);
		
		stringBuilder.append(netRecv);
		stringBuilder.append(separator);
		
		stringBuilder.append(netSendSpeed);
		stringBuilder.append(separator);
		stringBuilder.append(netRecvSpeed);
		
		return stringBuilder.toString();
	}

}
